'use strict';
define(['angular','treeView'], function(angular) {
	angular.module('backcenter.sysInfoSelectMulti', ['app.treeView'])

	.controller('sysInfoSelectMultiCtrl'
			,['$rootScope', '$scope', 'BizData', '$uibModalInstance','params', 'title'
			   , function($rootScope, $scope, BizData, $uibModalInstance, params, title
					   ) {

		var Model = this;
   	   	
   		$scope.appId = 'appId';
	    
		
		var options = {};
		options.container = Model;
		options.concept = 'SysInfo';
		options.name = 'dataSysInfo';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
		options.creater = '/backcenter/sysInfo/tree/create';
   		options.reader = '/backcenter/sysInfo/tree/query';
   		options.writer = '/backcenter/sysInfo/tree/save';
   		options.deleter = '/backcenter/sysInfo/tree/delete';
		options.idColumnDefine = "fID";
		options.idColumnName = "fID";
		options.isTree = true;
		options.parentRelation = 'fParent';
		options.nodeKindRelation = 'nodeKind';
		options.nodeLevelRelation = 'nodeLevel';
		options.nodeSortRelation = "sortNo";
		options.rootFilter = 'SysInfo.fParent is null';
		options.pathRelation = 'systemFullID';
		options.directDeleteMode = false;
		options.limit = -1;
		options.orderBy = 'sortNo ASC';
		
		options.onAfterRefresh = Model.dataSysInfoAfterRefresh;
		
		Model.dataSysInfo = new BizData(options);

		//////////////////////////////////////////////
		
        
		//////////////////////对话框使用开始//////////////////////////////////////
		
        //模态窗口打开之后执行的事件
        $uibModalInstance.opened.then(function(){
    		//接收调用对话框的参数
    		Model.title = title;  
    		Model.params = params;  
    		
//    	    Model.getServerAppOrgList();
			
    		Model.dataSysInfo.filter = "SysInfo.status='open' AND SysInfo.appId='"+$scope.appId+"'";
       		Model.dataSysInfo.refreshData();

        });  
        

		
        Model.ok = function () {  
	    	//保存成功
	    	//打包数据
	    	var event = {};
	    	var data = [];
	    	
	    	//循环data
			for(var index=0;index<Model.dataSysInfo.rows.length;index++){
				if(Model.dataSysInfo.rows[index].userdata.checked){
			    	
			    	var sourceRow = Model.dataSysInfo.rows[index];
			    	var row = {};
					//循环行中的列，判断变化点是哪一个
					for(var obj in sourceRow){
						if(obj!='$$hashKey' && obj!='userdata'){
							row[obj] = sourceRow[obj].value;
						}
					}
			    	
			    	data.push(row);
					
				}
			}
	    	
	    	event.data = data;
			$uibModalInstance.close(event);  
	    };  
	    
	    
	    Model.cancel = function () {  
	        $uibModalInstance.dismiss('cancel');  
	    };    
	    
	    //表格标题中的选择对话框ng-model
	    $scope.checkboxValue = false;
	    //表格标题中的选择对话框click事件
	    Model.checkboxClick = function () {  
			for(var index=0;index<Model.dataSysInfo.rows.length;index++){
				Model.dataSysInfo.rows[index].userdata.checked=$scope.checkboxValue;
			}
	    };    
		//////////////////////对话框使用结束//////////////////////////////////////


		
		
	    return Model;

	    
	    
	}])//控制器结束
	
	
});
